package com.openatc.agent.model;

import com.openatc.extend.common.config.array.IntArrayTypeDescriptor;
import lombok.Data;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Data
@Table(name = "vip_route")
@Entity
@EntityListeners(AuditingEntityListener.class)
@TypeDef(name = "typea",typeClass = IntArrayTypeDescriptor.class)
public class VipRoute {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

//    @Column(unique = true)
    private String name;
    @Column(columnDefinition = "int default 1")
    private Integer type;

    @CreatedDate
    @Column(updatable = false)
    private Date createtime;
    @LastModifiedDate
    private Date updatetime;

    @Type(type = "typea")
    private int[] month;
    @Type(type = "typea")
    private int[] day;
    @Type(type = "typea")
    private int[] date;

    private String starttime;

    private String endtime;

    @Column(columnDefinition = "int default 0")
    private int schedule;

//    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
//    @JoinColumn(name = "viprouteid",foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
//    @OrderBy("id ASC")
    @Transient
    private List<VipRouteDevice> devs;
    @Transient
    private int state;

    public VipRoute() {
    }

    public VipRoute(int id, String name){
        this.id = id;
        this.name = name;
    }


}
